package top.beiermode.geektime.projects.user.validator.bean.validation;

import top.beiermode.geektime.projects.user.domain.User;

import javax.validation.ConstraintViolation;
import javax.validation.Validation;
import javax.validation.Validator;
import javax.validation.ValidatorFactory;
import java.util.Set;

public class BeanValidationDemo {

    public static void main(String[] args) {
        ValidatorFactory factory = Validation.buildDefaultValidatorFactory();
        Validator validator = factory.getValidator();

        User user = new User();
        user.setName("123456");

        Set<ConstraintViolation<User>> violations = validator.validate(user);
        violations.forEach(c -> {
            System.out.println(c.getMessage());
        });
    }

}
